package org.eclipse.core.launcher;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import java.util.StringTokenizer;
import java.util.Vector;

/** 
 * Application is responsible for calling core launch api.
 * <p>
 * <b>Note:</b> This class/interface is part of an interim API that is still under 
 * development and expected to change significantly before reaching stability. 
 * It is being made available at this early stage to solicit feedback from pioneering 
 * adopters on the understanding that any code that uses this API will almost 
 * certainly be broken (repeatedly) as the API evolves.
 * </p>
 */

public class UIMain extends Main {
	private static final String DEFAULT_APPLICATION = "org.eclipse.ui.workbench";
/**
 * Creates a new instance of UIMain. This object can be used to run
 * the platform.  By default the application run using <code>UIMain</code>
 * is <code>org.eclipse.ui.workbench</code>.
 */
public UIMain() {
	super();
	application = DEFAULT_APPLICATION;
}
/**
 * Runs the platform with the given arguments.  If the arguments identify
 * an application to run (e.g., <code>-application com.example.application</code>),
 * that application is run.  Otherwise, the default application (<code>org.eclipse.ui.workbench</code>)
 * is run.   After running the application <code>System.exit(N)</code> is executed.
 * The value of N is derived from the value returned from running the application.
 * If the application's return value is an <code>Integer</code>, N is this value.
 * In all other cases, N = 0.
 * <p>
 * Clients wishing to run the platform without a following <code>System.exit</code>
 * call should use <code>run()</code>.
 * 
 * @param args the command-line arguments
 *
 * @see #run
 */
public static void main(String[] args) {
	Object result = null;
	try {
		result = new UIMain().run(args);
	} catch (Throwable e) {
		System.out.println("Exception launching the Eclipse Platform UI:");
		e.printStackTrace();
	}
	int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
	System.exit(exitCode);
}
/**
 * Runs the platform with the arguments specified in the given string.
 * 
 * @param argString the command-line arguments
 * @exception Exception thrown is a problem occurs during platform launching
 */
public static void main(String argString) throws Exception {
	Vector list = new Vector(5);
	for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();)
		list.addElement((String) tokens.nextElement());
	main((String[]) list.toArray(new String[list.size()]));
}
}
